import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

class ChangePasswordPage extends StatefulWidget {
  const ChangePasswordPage({super.key});

  @override
  State<ChangePasswordPage> createState() => _ChangePasswordPageState();
}

class _ChangePasswordPageState extends State<ChangePasswordPage> {
  final _oldPwdController = TextEditingController();
  final _newPwdController = TextEditingController();
  final _confirmPwdController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    final l10n = AppLocalizations.of(context)!;
    final theme = Theme.of(context);

    return Scaffold(
      appBar: AppBar(title: Text(l10n.changePasswordTitle)),
      body: ListView(
        padding: const EdgeInsets.all(16),
        children: [
          _buildPwdField(_oldPwdController, l10n.changePasswordOldPassword,
              Icons.lock_outline),
          const SizedBox(height: 16),
          _buildPwdField(
              _newPwdController, l10n.changePasswordNewPassword, Icons.lock),
          const SizedBox(height: 16),
          _buildPwdField(_confirmPwdController,
              l10n.changePasswordConfirmNewPassword, Icons.lock),
          const SizedBox(height: 32),
          FilledButton.icon(
            onPressed: _handleSave,
            icon: const Icon(Icons.check),
            label: Text(l10n.changePasswordConfirmChange),
          ),
        ],
      ),
    );
  }

  Widget _buildPwdField(TextEditingController c, String label, IconData icon) {
    final color = Theme.of(context).colorScheme;
    return TextField(
      controller: c,
      obscureText: true,
      decoration: InputDecoration(
        labelText: label,
        prefixIcon: Icon(icon, color: color.onSurfaceVariant),
        filled: true,
        fillColor: color.surfaceContainerHighest.withOpacity(0.3),
        border: OutlineInputBorder(
            borderRadius: BorderRadius.circular(12),
            borderSide: BorderSide.none),
      ),
    );
  }

  void _handleSave() {
    // TODO: 密码验证逻辑
    ScaffoldMessenger.of(context).showSnackBar(
      SnackBar(content: Text(AppLocalizations.of(context)!.changePasswordSuccess)),
    );
    Navigator.pop(context);
  }
}
